<?php 
namespace Phpcmf\Controllers;
$lei = (int)\Phpcmf\Service::L('Input')->get('lei'); 
if($lei==1){
    $lib_file = '/usr/local/xunsearch/sdk/php/lib/XS.php';
    require_once $lib_file;
}


class Sou extends \Phpcmf\Home\Module
{
    
    public function index() {
        
        
        
        $lei = (int)\Phpcmf\Service::L('Input')->get('lei'); 
        $v = (int)\Phpcmf\Service::L('Input')->get('v');
        $k = \Phpcmf\Service::L('Input')->get('k'); 
        
        
        if($lei == 1){
            $xs = new \XS('duixin');
            $search = $xs->search;
            //$search->setFuzzy()->setAutoSynonyms()->setQuery($k)->addRange('tid', $leixing, $leixing);
            $search->setFuzzy()->setAutoSynonyms()->setQuery($k);
            $search->setLimit(50); 
            $docs = $search->search();
            if(dr_is_app('sousuotongji')){
			$k = \Phpcmf\Service::L('input')->get('k');
			// 定义禁止的字符集  
			$forbidden_chars = "[，。；‘.￥%……&*（））#@！’“”]";
			
			if(!empty($k) && !preg_match("/[" . preg_quote($forbidden_chars, "/") . "]/u", $k)){
				
				d_sousuo_data($k,$this->uid,$tongji);
				
			}
		}
            
            $data= [];
            foreach ($docs as $sou) {
                $table = 'duixin_1_quan_form_son';
                $quantie = \Phpcmf\Service::M()->db->table($table)->where('id', $sou->id)->get()->getRowArray();
                $img = dr_get_content_img($quantie['neirong']);
                $imgs = [];
				   foreach ($img as $i => $tu) {
				        if($v==1){
				            $url = SITE_URL;
				            $yuanlais = 'uploadfile/';
				            $yuanlai = $url.$yuanlais.'&quot;';
				        } else {
				            
				            $yuanlais = '/uploadfile/';
				            $yuanlai = $yuanlais.'&quot;';
				        }
						
                        $tihuan = '';
                        $imgs[$i] = str_replace($yuanlai, $tihuan, $tu);
				        //$imgs[$i] = dr_thumb($tu);
				        //dr_debug('$imgs', $imgs);
				   }
                
                array_push($data,[
                    
                  'id'=>$sou->id,
                  'title'=>$search->highlight($sou->title),
                  'neirong'=>$search->highlight($sou->neirong),
                  'imgs'=>$imgs,
                  //dr_debug('搜索$data', $img),
                  //'summary'=>$search->highlight($sou->content),
                  //'summary'=>mb_substr($search->highlight($doc->content),0,130,'utf-8'),
                  'cid'=>$sou->cid,
                  'created_at'=>$sou->created_at,
                  'inputtime'=>$sou->inputtime,
                  'uid'=>$quantie['uid'],
                  'xiangsi'=>$sou->percent(), //相似度
                  'ids' => $sou->rank(), // 排列ids
                  'isDraft' => true,
                ]);
            }
            
            \Phpcmf\Service::V()->assign([
            'meta_title' => dr_lang('帖子搜索').SITE_SEOJOIN.SITE_NAME,
            'meta_keywords' => $this->get_cache('site', SITE_ID, 'config', 'SITE_KEYWORDS'),
            'meta_description' => $this->get_cache('site', SITE_ID, 'config', 'SITE_DESCRIPTION'),
            'data' => $data,
        ]);
            \Phpcmf\Service::V()->display('diysou.html');
        } else {
            \Phpcmf\Service::V()->assign([
            'meta_title' => dr_lang('帖子搜索').SITE_SEOJOIN.SITE_NAME,
            'meta_keywords' => $this->get_cache('site', SITE_ID, 'config', 'SITE_KEYWORDS'),
            'meta_description' => $this->get_cache('site', SITE_ID, 'config', 'SITE_DESCRIPTION')
        ]);
            \Phpcmf\Service::V()->display('sou.html');
        }

    }
    public function quan() {
		
	    \Phpcmf\Service::V()->assign([
	        'meta_title' => dr_lang($k.' - 圈子搜索').SITE_SEOJOIN.SITE_NAME,
	        'meta_keywords' => $this->get_cache('site', SITE_ID, 'config', 'SITE_KEYWORDS'),
	        'meta_description' => $this->get_cache('site', SITE_ID, 'config', 'SITE_DESCRIPTION')
	    ]);
	    \Phpcmf\Service::V()->display('sou_quan.html');
	}
	
}